<template>
	<el-dialog title=""  visible width="70%"  :show-close="false" :append-to-body="true" class="wrap" @close="cancel" :close-on-click-modal="false">
        	<i class="el-icon-close close" @click="cancel" style="color: white;z-index:10;"></i>
	    <div class="bt">添加学生</div>

        <div class="box cf">
        	<div class="left">
	            <div class="search">
	                <el-input class="input" v-model="vkeyword" placeholder="学生查询" icon="search" @keydown.enter.native="search"></el-input>
	                <el-button type="primary" class="btn" @click="search">搜索</el-button>
									<el-button type="success" class="btn"  @click="submit">添加</el-button>
	            </div>

	            <!-- 数据表格展示区域 -->
	            <el-table
	                :data="dataList"
	                ref="multipleTable"
	                border
	                align="center"
	                class="admin-table"
	                row-key="id"
	                @select="checkSelect"
	                @select-all="checkall">

	                <el-table-column
	                    type="selection"
	                    width="55"
	                    :reserve-selection="true"></el-table-column>


	                <el-table-column
	                    :prop="v.prop"
	                    :label="v.label"
	                    v-for="(v,index) in portTitleList"
	                    align="center"
	                    show-overflow-tooltip
	                    v-if="v.hide != 0"
	                    :formatter="v.formatter"
	                    :align="v.align || 'center'"
	                    :fixed="v.fixed"
	                    :class-name="v.columnStyle"
	                    :width="v.width"
	                    :min-width="v.minWidth"
	                    :header-align="v.headerAlign || 'center'"
	                    >
	                    <template scope="scope">
	                        <div slot="reference">
		                        <img
		                        :src="scope.row.xb == '男' ? $store.state.sexImg.boy : $store.state.sexImg.girl"
		                        style="width:20px;vertical-align:middle;"
		                        v-if="scope.column.property == 'zwm'">
		                        <span style="vertical-align:middle;">{{ scope.row[scope.column.property] }}</span>
		                    </div>
	                     </template>
	                </el-table-column>
	            </el-table>

	            <!-- 分页查询区域 -->
	            <el-pagination
	                @size-change="handleSizeChange"
	                @current-change="handleCurrentChange"
	                :current-page.sync="pageindex"
	                :page-sizes="pagesizes"
	                :page-size="pagesize"
	                :layout="layout"
	                :total="total"
	                class="class-page">
	            </el-pagination>
	        </div>

	        <div class="right">
	            <div class="choose">
	            	<!-- <div class="first">
	            		<div>
                            <span>已选择:</span>
                            <span class="number">{{multipleList.length}}</span>
                        </div>
                        <span class="del el-icon-delete" @click="del()">
                            <i></i>
                        </span>
	            	</div> -->
	                <ul class="header">
	                    <li class="first">
	                        <div>
	                            <span>已选择:</span>
	                            <span class="number">{{multipleList.length}}</span>
	                        </div>
	                        <span class="del el-icon-delete" @click="del()">
	                            <i></i>
	                        </span>
	                    </li>
	                    <li v-for="(v,index) in multipleList">
	                        <span class="name ellipsis">{{v.zwm}}</span>
	                        <span class="del el-icon-delete" @click="del(multipleList[index])">
	                            <i></i>
	                        </span>
	                    </li>
	                </ul>
	            </div>
	        </div>
        </div>


	</el-dialog>
</template>

<script>
import qs from 'qs'
    export default {
        props: ['params'],
        data () {
            return {
                vkeyword:'',
                multipleList: [],
                dataList: [],  //表格数据

                /*
                    prop :  接口参数名
                    label : 接口中文名
                    hide : 是否隐藏这一列
                    align : 这一列对齐顺序 ： left,right,center
                    headerAlign : 这一列表头对齐方式 ： left,right,center
                */
                portTitleList: [
                    {
                        prop:'id',
                        label:'ID',
                        hide:0,
                        align:'center',
                        fixed:false,
                        width:'',
                        minWidth:'',
                        headerAlign:'center',
                        formatter: function(row,column) {}
                    },
                    {
                        prop:'zwm',
                        label:'中文名',
                        hide:1,
                        align:'center',
                        fixed:false,
                        width:'',
                        minWidth:'',
                        headerAlign:'center',
                        formatter: function(row,column) {}
                    },
                    {
                        prop:'ysbjmc',
                        label:'班级名称',
                        hide:1,
                        align:'center',
                        fixed:false,
                        width:'',
                        minWidth:'',
                        headerAlign:'center',
                        formatter: function(row,column) {}
                    },
                    {
                        prop:'dh',
                        label:'电话',
                        hide:1,
                        align:'center',
                        fixed:false,
                        width:'',
                        minWidth:'',
                        headerAlign:'center',
                        formatter: function(row,column) {}
                    },
                    {
                        prop:'csrq',
                        label:'出生日期',
                        hide:1,
                        align:'center',
                        fixed:false,
                        width:'',
                        minWidth:'',
                        headerAlign:'center',
                        formatter: function(row,column) {}
                    }

                ],

                /*动画加载*/
                isLoading: false,//动画加载
                searchLoading: false,//搜索按钮触发按钮动画

                /*模糊搜索条件*/
                inputmc:'' , //  班级名称,

                /*分页属性设置*/
                layout: 'total, sizes, prev, pager, next, jumper',//组件布局
                pageindex: 1,//当前分页页码
                pagesizes: [6, 12, 18, 24],//显示个数的选择器选项
                pagesize: 6,//每页显示条目数
                total: 0,//总条数

                dropDownData:'', //
            }
        },
        created () {

            //加载页面时调用
						if(this.params){
								this.ysbjid = this.params.row.id
						}else{
								this.ysbjid = this.$route.query.iid
						}
						this.search();//分页获取默认数据
        },
        mounted () {
            //开始了哦
        },
        methods: {

            search () {//查询搜索触发事件
                this.searchLoading = true;
                var logininfo = JSON.parse(localStorage.logininfo);
								var params3 = qs.stringify({
										ysbjid:this.ysbjid,
										keyword: this.vkeyword+'',
										pageindex: this.pageindex,
										pagesize: this.pagesize,
										yhid:logininfo.id,
										xxid:logininfo.xxid
								});
                this.axios.post(this.$store.state.api + 'xs/getysbjxs',params3)
								.then( res => {
                    let data = res.data.data;
                    let list = data.list;
                    this.total = data.totalPage;
                    this.dataList = list;
                    this.searchLoading = false;
                }).catch( res => {
                    console.log(res)
                    this.searchLoading = false;
                })
            },

            submit () {

                this.multipleList.forEach( v => {
                	var logininfo = JSON.parse(localStorage.logininfo);
									var params3 = qs.stringify({
										yhid:logininfo.id+'',
										 xxid:logininfo.xxid+'',
										 ysbjid: this.ysbjid+'',
										 xsids: v.id+''
									});
                    this.axios.post(this.$store.state.api + 'bj/updateysbjxs',params3)
										.then( res => {
                        if (res.data.code == 1) {
                            this.$emit('close',{type:'add2',cancel:false})
                        }else{
                            this.$message.warning(res.data.msg)
                        }
                    }).catch( res => {
                        this.$message.warning("服务器异常")
                    })
                })

            },

            del (obj) {
                if (obj) {
                    this.$refs.multipleTable.toggleRowSelection(obj,false);
                }else{
                    this.$refs.multipleTable.clearSelection();
                    this.multipleList = [];
                }

            },

            handleSizeChange (val) {//每页显示条数触发事件
                this.pagesize = val;
                this.pageindex = 1;
                this.search();
            },

            handleCurrentChange (val) {//分页触发事件
                this.search();
            },
            checkSelect (selection, row) {//点击单选select触发事件
                this.multipleList = selection;
            },
            checkall (selection) {//点击全选select触发事件
                this.multipleList = selection;
            },

            cancel () {
               this.$emit('close',{type:'add2',cancel:true})
            }

        }
    }
</script>

<style lang="less" scoped>
.wrap {
		.input-block {
			margin-bottom: 20px;
			text-align: center;
		}
		.bt{
		position: absolute;
		width: 100%;
		height: 50px;
		margin: 0 auto;
		top: 0;
		left: 0;
		background: #50BFFF;
		color:white;
		text-align:left;
		line-height: 50px;
		font-size: 17px;
		padding-left: 15px;
	}
		}

	.box {
		overflow: auto;
		height:500px;
		max-height: 500px;
	}
    .left, .right {
        // display: inline-block;
        float: left;
        vertical-align: top;
    }
    .left{
        width: 70%;
        min-width:440px;
    }
    .right {
        // width: 240px;
        width: 25%;
        height: 100%;
        margin-left:20px;
        overflow: auto;
        position: relative;

        .choose {
            box-shadow:0px 0px 10px #969696;
            border-radius:10px;
        }

        .first {
    		display:flex;
            align-items:center;
            justify-content: space-between;
            padding:10px 20px;
        	width: 100%;
            background: #EEF1F4;

            .number {
                min-width: 10px;
                padding:2px 7px;
                font-weight: 700;
                border-radius:10px;
                background: #969c9c;
                color: #fff;
            }
        }
        .header{
            li{
                display:flex;
                align-items:center;
                justify-content: space-between;
                padding:10px 20px;

                .del {
                    cursor: pointer;
                    position: relative;

                    &:hover i {
                        position: absolute;
                        left:50%;top:50%;
                        transform: translate(-50%, -50%);
                        width: 25px;
                        height: 25px;
                        border-radius: 50%;
                        background: rgba(0,0,0,0.2);
                    }
                }

            }



        }
    }
	.input {
		width:200px;
	}
	.btn {
		width:80px;
		margin-left:20px;
		padding:7px 15px;
	}

	.admin-table {
		margin-top:10px;
	}

	h2{
		line-height: 30px;
		text-align: center;
	}

	.class-page {
		margin-top:10px;
	}

	.submit {
		// float: right;
		display: block;
		margin:0 auto;
		margin-top:20px;
	}
</style>
